package com.leo.ibatis.demo.service.impl;

import java.util.List;

import com.leo.ibatis.demo.base.Service;
import com.leo.ibatis.demo.criteria.SequenceCriteria;
import com.leo.ibatis.demo.dao.SequenceDao;
import com.leo.ibatis.demo.domain.Sequence;
import com.leo.ibatis.demo.service.SequenceService;

public class SequenceServiceImpl extends Service implements SequenceService {

	private SequenceDao sequenceDao;

	public void setSequenceDao(SequenceDao sequenceDao) {
		this.sequenceDao = sequenceDao;
	}

	public void insert(Sequence sequence) {
		sequenceDao.insert(sequence);
	}

	public int update(Sequence sequence) {
		int actualRowsAffected = 0;
		
		String name = sequence.getName();

		Sequence _oldSequence = sequenceDao.select(name);
		
		if (_oldSequence != null) {
			actualRowsAffected = sequenceDao.update(sequence);
		}
		
		return actualRowsAffected;
	}

	public int delete(String name) {
		int actualRowsAffected = 0;
		
		Sequence _oldSequence = sequenceDao.select(name);
		
		if (_oldSequence != null) {
			actualRowsAffected = sequenceDao.delete(name);
		}
		
		return actualRowsAffected;
	}
	
	public Sequence select(String name) {
		return sequenceDao.select(name);
	}

	public List<Sequence> list(SequenceCriteria sequenceCriteria) {
		return sequenceDao.list(sequenceCriteria);
	}
	
	public List<Sequence> listOnPage(SequenceCriteria sequenceCriteria) {
		return sequenceDao.listOnPage(sequenceCriteria);
	}

}
